﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Weazel.Badger.Vhdl
{
  public class FileDeclaration : IProcessDeclarativeItem
  {
    public enum FileType
    {
      Text
    };

    public enum FileMode
    {
      Write,
      Read,
      Append
    };

    private FileType type;
    private FileMode mode;
    private string filename;
    private string identifier;

    public FileDeclaration(string identifier, FileType type, FileMode mode, string filename)
    {
      this.identifier = identifier;
      this.type = type;
      this.mode = mode;
      this.filename = filename;
    }

    private string modeToString(FileMode mode)
    {
      switch (mode)
      {
        case FileMode.Append: return "append_mode";
        case FileMode.Read: return "read_mode";
        case FileMode.Write: return "write_mode";

        default:
          throw new NotSupportedException();
      }
    }

    private string typeToString(FileType type)
    {
      switch (type)
      {
        case FileType.Text: return "text";

        default:
          throw new NotSupportedException();
      }
    }

    public void Write(System.CodeDom.Compiler.IndentedTextWriter writer)
    {
      string result = 
        string.Format(
          "file {0} : {1} open {2} is \"{3}\";", 
          identifier,
          typeToString(type),
          modeToString(mode),
          filename
        );

      writer.WriteLine(result);
    }
  }
}
